package com.itheima.order.controller;

import com.itheima.order.entity.User;
import com.itheima.order.feign.UserFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {
    /*@Autowired
    private RestTemplate restTemplate;

    @Autowired
    private DiscoveryClient discoveryClient;*/

    /*@RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public User findById(@PathVariable Long id) {
        List<ServiceInstance> instances = discoveryClient.getInstances("service-user");
        *//*for (ServiceInstance instance : instances) {
            System.out.println(instance);
        }*//*
        ServiceInstance instance = instances.get(0);
        User user = restTemplate.getForObject("http://"+instance.getHost()+":"+ instance.getPort()+"/user/" + id, User.class);
        return user;
    }*/
    @Autowired
    private UserFeignClient userFeignClient;

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public User findById(@PathVariable Long id) {
        User user = userFeignClient.findById(id);
        return user;
    }

}
